package sprites;

import controlador.GestorDeDibuix;
import java.awt.Point;
import java.util.Random;

/**
 *
 * @author Carlos Moya Martinez
 */
public class EsferaR extends PlayableElement {

    boolean right = false;
    Random random = new Random();

    public EsferaR(Point pantalla) {
        super(1, true, pantalla);
        this.x = (int) this.pantalla.getX();
        this.y = this.randInRangeInc(0, (int) this.pantalla.getY() / 2);
        this.dimX = 30;
        this.dimY = 30;
        this.enemic = true;
        this.puntos = 1;
    }

    @Override
    public void animar() {
        if (random.nextBoolean()) {
            if (this.y < pantalla.y-(this.y/2)) {
                this.y = this.y + 4;
            } else {
                this.y = this.y - 4;
            }
        } else {
            if (this.y > this.y/2) {
                this.y = this.y - 4;
            } else {
                this.y = this.y + 4;
            }

        }

        if (right) {
            if (this.x < this.pantalla.getX()-dimX) {
                this.x = this.x + 4;
            } else {
                this.right = false;
                this.x = this.x - 4;
            }
        } else {
            if (this.x > 0) {
                this.x = this.x - 4;
            } else {
                this.right = true;
                this.x = this.x + 4;
            }
        }
    }

    @Override
    public void pintar() {
        GestorDeDibuix.getInstancia().pintar("BOLAR", getX(), getY(), dimX, dimY);
    }

    private int randInRangeInc(int min, int max) {
        return min + (int) (Math.random() * (max - min));
    }
}
